#include "llt_v4tov6.hh"

using namespace userFunction;

void
v4tov6::processData(lee::PktData * const pkt)
{
  tt::Packet * v4pkt;
  v4pkt = static_cast<tt::Packet *>(pkt);
  tt::SixPacket * v6pkt = new tt::SixPacket;

  // set the version, traffic class, and flow label
  // use the the type of service for the traffic class
  v6pkt->ipHdr.ip6_vfc = 0x6 && (v4pkt->ipHdr.tos << 4);
  
  // copy ttl to the hop limit field
  v6pkt->ipHdr.ip6_hlim = v4pkt->ipHdr.ttl;

  // copy protocol to the next header field
  v6pkt->ipHdr.ip6_nxt = v4pkt->ipHdr.protocol;

  // payload length is packet size minus ipv4 header size
  // (plus options which we are ignoring for the moment)
  v6pkt->ipHdr.ip6_plen = v4pkt->ipHdr.tot_len - 20;
  
  // translate source address
  v6pkt->ipHdr.ip6_src.s6_addr32[0] = v4pkt->ipHdr.saddr;
  for(int i = 1; i < 4; ++i) {
    v6pkt->ipHdr.ip6_src.s6_addr32[i] = 0x0;
  }

  // translate destination address
  v6pkt->ipHdr.ip6_dst.s6_addr32[0] = v4pkt->ipHdr.daddr;
  for(int i = 1; i < 4; ++i) {
    v6pkt->ipHdr.ip6_dst.s6_addr32[i] = 0x0;
  }
  normal(static_cast<lee::PktData *>(v6pkt));
  drop(pkt);
  return;
}
